package com.example.venue_reservation_service.controller;

import com.example.venue_reservation_service.dto.MessageDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

@RestController
@RequestMapping("/message")
@Api("预约通知管理")
@CrossOrigin
public class MessageController {

    private final SimpMessagingTemplate messagingTemplate;

    public MessageController(SimpMessagingTemplate messagingTemplate) {
        this.messagingTemplate = messagingTemplate;
    }

    // 发送消息到指定用户
    @GetMapping("/send")
    public String sendMessageToUser(@RequestParam("userId") Integer userId) {
        MessageDTO message = new MessageDTO();
        message.setUserId(userId);
        message.setContent("测试");
        String destination = "/queue/messages/" + userId;
        messagingTemplate.convertAndSend(destination, message);
        return "消息已发送给用户ID: " + userId;
    }

}